// 获取本周的日期，从
import moment from "moment";
import formatDate from "./formatDate";

const curWeek=()=>{
    let dateObj={
        start:'',
        end:'',
    }

    const time=new Date()
    const day=time.getDay();
    if(day===0){
        // 获取前面6天的日期
        dateObj.start=new Date(time.setDate(time.getDate()-6));
        dateObj.end=new Date();

    }
    if(day===1){
        // 获取后面6天
        dateObj.start=new Date();
        dateObj.end=new Date(time.setDate(time.getDate()+6));

    }
    if(day===2){
        // 获取前面1天，后面5天
        dateObj.start=new Date(time.setDate(time.getDate()-1));
        dateObj.end=new Date(time.setDate(time.getDate()+5));
    }
    if(day===3){
        // 获取前面2天，后面4天
        dateObj.start=new Date(time.setDate(time.getDate()-2));
        dateObj.end=new Date(time.setDate(time.getDate()+4));
    }
    if(day===4){
        // 获取前面3天，后面3天
        dateObj.start=new Date(time.setDate(time.getDate()-3));
        dateObj.end=new Date(time.setDate(time.getDate()+3));
    }
    if(day===5){
        // 获取前面4天，后面2天
        dateObj.start=new Date(time.setDate(time.getDate()-4));
        dateObj.end=new Date(time.setDate(time.getDate()+2));
    }
    if(day===6){
        // 获取前面5天，后面1天
        dateObj.start=new Date(time.setDate(time.getDate()-5));
        dateObj.end=new Date(time.setDate(time.getDate()+1));
    }

    // 拿时间戳，
    let startStr=formatDate(dateObj.start.getTime()) 
    let endStr=formatDate(dateObj.end.getTime())

    return [moment(startStr, 'YYYY-MM-DD'), moment(endStr, 'YYYY-MM-DD')]
}
export default curWeek;